/**
 * Linux 下为 chrome-sandbox 设置 root 用户 4755 权限
 */
const fs = require('fs');
const path = require('path');

exports.default = async function(context) {
  const appOutDir = context.appOutDir;  // 应用输出目录
  const chromeSandboxPath = path.join(appOutDir, 'chrome-sandbox');

  console.log('Running afterPack to adjust chrome-sandbox permissions...');

  try {
    // 设置 chrome-sandbox 文件的权限为 root 并将其设置为 4755 权限
    fs.chownSync(chromeSandboxPath, 0, 0); // 设置 owner 为 root:root
    fs.chmodSync(chromeSandboxPath, 0o4755); // 设置权限为 4755
    console.log('chrome-sandbox permissions updated successfully.');
  } catch (err) {
    console.error('Failed to set chrome-sandbox permissions:', err);
  }
};
